//
//  CellTableViewSection2For2.m
//  ProjectA
//
//  Created by dllo on 16/1/22.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "CellTableViewSection2.h"
#import "ModelForSection2.h"
#import <UIImageView+WebCache.h>
#import "UIView+NightManager.h"
#import "AppMacro.h"
@interface CellTableViewSection2 ()

@property (nonatomic, strong) UIView *viewForBg;
@property (nonatomic, strong) UIView *view;
@property (nonatomic, strong) UIImageView *cover_image_w640; //背景
@property (nonatomic, strong) UILabel *name;       //东京迷失
@property (nonatomic, strong) UILabel *first_day;  //2015.12.31
@property (nonatomic, strong) NSNumber *day_count;  //5天
@property (nonatomic, strong) NSNumber *view_count; //3653浏览
@property (nonatomic, strong) UILabel *popular_place_str;  //日本, 台东区
@property (nonatomic, strong) NSDictionary *user;
@property (nonatomic, strong) UILabel *user_name;
@property (nonatomic, strong) UIImageView *user_cover;
@property (nonatomic, strong) UILabel *label1;
@property (nonatomic, strong) UILabel *label2;
@end

@implementation CellTableViewSection2

- (void)dealloc {
    
    [_viewForBg release];
    [_view release];
    [_cover_image_w640 release];
    [_name release];
    [_first_day release];
    [_day_count release];
    [_view_count release];
    [_popular_place_str release];
    [_user release];
    [_user_name release];
    [_user_cover release];
    [_label1 release];
    [_label2 release];
    [super dealloc];
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}
- (void)createSubView {
    self.user = [NSDictionary dictionary];
    
    self.view = [[UIView alloc] init];
    [self.contentView addSubview:self.view];
    [self.view release];
    
    self.cover_image_w640 = [[UIImageView alloc] init];
    [self.view addSubview:self.cover_image_w640];
    [self.cover_image_w640 release];
    
    self.viewForBg = [[UIView alloc] init];
    [self.cover_image_w640 addSubview:self.viewForBg];
    [_viewForBg release];
    self.viewForBg.backgroundColor = [UIColor blackColor];
    self.viewForBg.alpha = 0.2f;
    
    self.name = [[UILabel alloc] init];
    [self.cover_image_w640 addSubview:self.name];
    [_name release];
    
    self.first_day = [[UILabel alloc] init];
    [self.cover_image_w640 addSubview:self.first_day];
    [_first_day release];
    
    self.popular_place_str = [[UILabel alloc] init];
    [self.cover_image_w640 addSubview:self.popular_place_str];
    [_popular_place_str release];
    
    self.user_name = [[UILabel alloc] init];
    [self.cover_image_w640 addSubview:self.user_name];
    [_user_name release];
    
    self.user_cover = [[UIImageView alloc] init];
    [self.cover_image_w640 addSubview:self.user_cover];
    [_user_cover release];
    
    self.label1 = [[UILabel alloc] init];
    [self.cover_image_w640 addSubview:self.label1];
    [_label1 release];
    
    self.label2 = [[UILabel alloc] init];
    [self.cover_image_w640 addSubview:self.label2];
    [_label2 release];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.view.frame = CGRectMake(10, 5, self.frame.size.width - 20, self.frame.size.height - 10);
    
    self.cover_image_w640.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    self.cover_image_w640.layer.cornerRadius = 7;
    self.cover_image_w640.layer.masksToBounds = YES;
    
    self.viewForBg.frame = self.cover_image_w640.frame;
    
    self.name.frame = CGRectMake(15, 5, self.view.frame.size.width - 50, 30);
    [self.name setTextColor:[UIColor whiteColor]];
    
    if ([self.first_day.text isEqualToString:@""]) {
        self.label1.frame = CGRectZero;
    } else {
        self.label1.frame = CGRectMake(15, 5 + self.name.frame.size.height, 3, 15);
        self.label1.layer.cornerRadius = 3;
        self.label1.layer.masksToBounds = YES;
        self.label1.backgroundColor = RGBA(68, 177, 207, 1);
    }
    
    
    if ([self.popular_place_str.text isEqualToString:@""]) {
        self.label2.frame = CGRectZero;
        
    } else {
        self.label2.frame = CGRectMake(15, 5 + self.name.frame.size.height + 10, 3, 20);
        self.label2.layer.cornerRadius = 3;
        self.label2.layer.masksToBounds = YES;
        self.label2.backgroundColor = RGBA(68, 177, 207, 1);
    }
    
    
    self.first_day.frame = CGRectMake(25, 5 + self.name.frame.size.height, self.view.frame.size.width - 50, 15);
    self.first_day.font = [UIFont systemFontOfSize:13];
    [self.first_day setTextColor:[UIColor whiteColor]];
    
    self.popular_place_str.frame = CGRectMake(25, 5 + self.name.frame.size.height + 15, self.view.frame.size.width - 50, 15);
    self.popular_place_str.font = [UIFont systemFontOfSize:13];
    [self.popular_place_str setTextColor:[UIColor whiteColor]];
    
    self.user_cover.frame = CGRectMake(15, self.view.frame.size.height - 30 - 15, 30, 30);
    self.user_cover.layer.cornerRadius = 15;
    self.user_cover.layer.masksToBounds = YES;
    
    self.user_name.frame = CGRectMake(50, self.view.frame.size.height - 30 - 15, 100, 30);
    self.user_name.font = [UIFont systemFontOfSize:13];
    [self.user_name setTextColor:[UIColor whiteColor]];
    
}

- (void)passModel:(ModelForSection2 *)model {
    
    
    [self.cover_image_w640 sd_setImageWithURL:[NSURL URLWithString:model.cover_image_w640] placeholderImage:[UIImage imageNamed:@"iconfont-zhanweitu"]];
    self.name.text = model.name;
    self.first_day.text = [NSString stringWithFormat:@"%@  %@ 天  %@ 浏览",model.first_day, model.day_count, model.view_count];
    self.popular_place_str.text = model.popular_place_str;
    [self.user_cover sd_setImageWithURL:[NSURL URLWithString:[model.user objectForKey:@"cover"]]];
    
    self.user_name.text = [model.user objectForKey:@"name"];
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
